﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Common_Library.Infrastructure;
using Common_Library.Parts_of_map;

namespace GamePlay_Preview.PlayersTools
{
    public class PlayerState
    {
        //public static int MOVE_LENGTH = 2;
        public static int STATE_LENGTH = 6;

        //public List<int> Move { get; set; }
        public MoveType MoveType { get; set; }
        public Directions MoveDirection { get; set; }
        public List<int> State { get; set; }
        public double PlayerScore { get; set; }
        public MoveConsequence ConsequenceOfMove { get; set; }

        public PlayerState()
        {
            //Move = new List<int>(MOVE_LENGTH);
            State = new List<int>(STATE_LENGTH);
            PlayerScore = 0;

            //for (int i = 0; i < MOVE_LENGTH; i++)
            //    Move.Add(0);
            for (int i = 0; i < STATE_LENGTH; i++)
                State.Add(0);
        }

        /// <summary>
        /// Sprawdza roznice miedzy dwoma stanami
        /// </summary>
        /// <param name="state1"></param>
        /// <param name="state2"></param>
        /// <returns></returns>
        public static bool IsStatesEqual(PlayerState state1, PlayerState state2)
        {
            //ConsoleWriter.DisplayStatesComparison(state1, state2);
            for (int i = 0; i < STATE_LENGTH; i++)
                if (state1.State[i] != state2.State[i])
                    return false;
            return true;
        }

        /// <summary>
        /// Sprawdza roznice miedzy dwoma akcjami (move)
        /// </summary>
        /// <param name="state1"></param>
        /// <param name="state2"></param>
        /// <returns></returns>
        public static bool IsMovesEqual(PlayerState state1, PlayerState state2)
        {
            //for (int i = 0; i < MOVE_LENGTH; i++)
            //    if (state1.Move[i] != state2.Move[i])
            //        return false;
            //return true;
            if (state1.MoveType != state2.MoveType || state1.MoveDirection != state2.MoveDirection)
                return false;
            return true;
        }

        public override string ToString()
        {
            var returnString = "Ruch " + MoveType + " kierunek " + MoveDirection + " konsekwencja ruchu " + ConsequenceOfMove +
                               " i stan ";
            foreach (var i in State)
            {
                returnString += i.ToString();
            }
            return returnString;
        }
    }
}
